import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { getMonthDays, getToday } from "@/utils/getData";
import res from "@/TestData/detial.json";
export const useDataStore = defineStore("data", () => {
  const year = ref(new Date().getFullYear());
  const month = ref(new Date().getMonth() + 1);
  const monthDays = computed(() => getMonthDays(year.value, month.value));
  const getMonthDay = (year, month) => {
    return (monthDays.value = getMonthDays(year, month));
  };
  const chooseDay = ref(getToday());
  const today = computed(() => getToday());
  const setChooseDay = (day) => {
    chooseDay.value = day;
  };
  const setYear = (years) => {
    year.value = years;
  };
  const setMonth = (months) => {
    month.value = Number(months);
  };
  const toToday = () => {
    year.value = new Date().getFullYear();
    month.value = new Date().getMonth() + 1;
    chooseDay.value = getToday();
  };
  const prevMonth = () => {
    if (month.value === 1) {
      year.value--;
      month.value = 12;
    } else {
      month.value--;
    }
  };
  const nextMonth = () => {
    if (month.value === 12) {
      year.value++;
      month.value = 1;
    } else {
      month.value++;
    }
  };
  const detial = computed(() => {
    //axios.get('http://localhost:3000/detial.json').then(res=>{
    //  return res.data
    //}).catch(err=>{
    //  console.log(err)
    //})
    return res.result.data;
  });
  return {
    monthDays,
    getMonthDay,
    chooseDay,
    setChooseDay,
    today,
    year,
    month,
    setYear,
    setMonth,
    toToday,
    prevMonth,
    nextMonth,
    detial
  };
});
